package com.longdaji.decoration.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.bean.Integral;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Kanade on 2018/4/7 0007.
 */

public class IntegralAdapter extends RecyclerView.Adapter<IntegralAdapter.IntegralHolder> {
    private List<Integral> mIntegralList = new ArrayList<>();
    private Context mContext;

    public IntegralAdapter(List<Integral> integralList) {
        this.mIntegralList = integralList;
    }

    class IntegralHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_integral_price)
        TextView tvPrice;
        @BindView(R.id.tv_integral_base)
        TextView tvBase;
        @BindView(R.id.tv_integral_content)
        TextView tvContent;
        @BindView(R.id.tv_integral_overdue)
        TextView tvOverdue;
        @BindView(R.id.btn_receive_integral)
        Button btnReceiveIntegral;

        public IntegralHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @OnClick({R.id.btn_receive_integral})
        void onItemViewClicked(View view) {
            switch (view.getId()) {
                case R.id.btn_receive_integral:
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public IntegralHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_receive_integral, parent, false);
        IntegralHolder holder = new IntegralHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(IntegralHolder holder, int position) {
        Integral integral = mIntegralList.get(position);
        holder.tvPrice.setText(String.valueOf(integral.getPrice()));
        holder.tvBase.setText("满" + String.valueOf(integral.getBase()) + "使用");
        holder.tvContent.setText(integral.getContent());
        holder.tvOverdue.setText(integral.getOverdue() + "过期");
        holder.btnReceiveIntegral.setText(integral.getRecevingState());
    }

    @Override
    public int getItemCount() {
        return mIntegralList.size();
    }

    public void setData(List<Integral> list) {
        mIntegralList.clear();
        mIntegralList.addAll(list);
        notifyDataSetChanged();
    }
}
